import Vue from 'vue'
import VueRouter from 'vue-router'

import login from '../views/login.vue'
import regist from '../views/regist.vue'
import home from '../views/home.vue'
import datas from '../views/datas.vue'
import chart from '../views/chart.vue'
import zdata from '../views/zdata.vue'

Vue.use(VueRouter)

const routes = [{
	path: '',
	name: '登录',
	component: login
}, {
	path: '/login',
	name: '登录',
	component: login
}, {
	path: '/regist',
	name: '注册',
	component: regist
}, {
	path: '/zdata',
	name: '大屏',
	component: zdata
}, {
	path: '/home',
	name: '主页',
	component: home,
	redirect: '',
	children: [{
		path: '/datas',
		name: '数据',
		component: datas,
		meta: {
			keepAlive: true
		}
	}, {
		path: '/chart',
		name: '图表',
		component: chart,
		meta: {
			keepAlive: true
		}
	}]
}];

const router = new VueRouter({
	//mode: 'history',
	routes: routes
})

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
	return originalPush.call(this, location).catch(err => err)
}

router.beforeEach((to, from, next) => {
	var token = sessionStorage.getItem('token');
	/* if (to.path != '/' && to.path != '/login') {
		if (token === null || token === "") {
			router.push('/');
			return;
		}
	} */
	next();
})

router.afterEach((to, from) => {

})

export default router
